package com.wheesper.www.WheesperServer.Net.Session;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.ArrayList;
import java.util.List;

import com.wheesper.www.WheesperServer.Net.Chat.ChatRoom;

import io.netty.channel.Channel;

public class IOSession extends Session{
	private ConcurrentHashMap<Integer,ChatRoom> _joinedChatRoom;
	
	public IOSession(Integer _sessionId, Channel _channel) {
		super(_sessionId, _channel);
		_joinedChatRoom = new ConcurrentHashMap<Integer,ChatRoom>();
	}

	@Override
	public void send(String msg) {
		//TODO:
	}

	@Override
	public void join(ChatRoom chatRoom) {
		_joinedChatRoom.put(chatRoom.getID(), chatRoom);
		chatRoom.register(this);
	}

	@Override
	public void left(ChatRoom chatRoom) {
		_joinedChatRoom.remove(chatRoom.getID());
		chatRoom.deregister(this);
	}

	public void disconneted() {
		_joinedChatRoom.forEach(new BiConsumer<Integer,ChatRoom>() {
			@Override
			public void accept(Integer t, ChatRoom u) {
				u.deregister(IOSession.this);
			}
			
		});
		_joinedChatRoom.clear();
	}
}
